package com.example.exam.controller;

import com.example.exam.entity.ExamPaperAnswer;
import com.example.exam.service.DataAnalysisService;
import com.example.exam.service.QuestionAnswerService;
import com.example.exam.util.ResultVOUtil;
import com.example.exam.vo.InfoVO;
import com.example.exam.vo.QuestionAnalysisVO;
import com.example.exam.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author shishuqian
 * date 2021/4/28
 * time 17:11
 **/
@RestController
@RequestMapping("/dataAnalysis")
@Api(value = "数据分析controller",tags = {"对某一份试卷,分析用户填写的数据"})
public class DataAnalysisController {

    @Autowired
    private QuestionAnswerService questionAnswerService;

    @Autowired
    private DataAnalysisService dataAnalysisService;

    //获取所有用户填写选择题，判断题信息等信息
    @ApiOperation(value = "根据试卷id查询试卷的填写情况")
    @ApiResponses({@ApiResponse(code = 200,message = "OK",response = QuestionAnalysisVO.class)})
    @GetMapping("/countQuestionResult/{examPaper_id}")
    public ResultVO countQuestionResult(@PathVariable("examPaper_id") Integer examPaper_id){
        return ResultVOUtil.success(questionAnswerService.countQuestionResult(examPaper_id));
    }

    //获取词云图
    @GetMapping("/getWordCloud/{question_id}")
    public ResultVO getWordCloud(@PathVariable("question_id") Integer question_id){
        return ResultVOUtil.success(dataAnalysisService.wordCloud(question_id));
    }


    @ApiOperation(value = "根据试卷id查询填写此试卷的人数")
    @ApiResponses({@ApiResponse(code = 200,message = "OK",response = Integer.class)})
    @GetMapping("/countFilledPeople/{examPaper_id}")
    public ResultVO countFilledPeople(@PathVariable("examPaper_id") Integer examPaper_id){
        return ResultVOUtil.success(questionAnswerService.countFilledPeople(examPaper_id));
    }

    @GetMapping("/countText/{questionId}")
    public ResultVO queryText(@PathVariable("questionId") Integer questionId){
        List<InfoVO> list = questionAnswerService.queryAllAnswer(questionId);
        return ResultVOUtil.success(list);
    }

    @GetMapping("/getNameDan/{questionId}/{userAnswer}")
    public ResultVO findNameDan(@PathVariable("questionId") Integer questionId,
                               @PathVariable("userAnswer") String userAnswer){
        List<String> names = dataAnalysisService.findNameDan(questionId, userAnswer);
        return ResultVOUtil.success(names);
    }


    @GetMapping("/getNameDuo/{questionId}/{userAnswer}")
    public ResultVO findNameDuo(@PathVariable("questionId") Integer questionId,
                                @PathVariable("userAnswer") String userAnswer){
        List<String> names = dataAnalysisService
                .findNameDuo(questionId, userAnswer, userAnswer + "$_%", "%$_" + userAnswer, "%$_" + userAnswer + "$_%");
        return ResultVOUtil.success(names);
    }

    @GetMapping("/viewRanking/{examPaperId}")
    public ResultVO viewRanking(@PathVariable("examPaperId") Integer examPaperId){
        List<ExamPaperAnswer> examPaperAnswerList = questionAnswerService.viewRanking(examPaperId);
        return ResultVOUtil.success(examPaperAnswerList);
    }

}
